package com.zhihuixingguang.login;

import com.zhihuixingguang.util.JSONUtil;
import com.zhihuixingguang.util.MD5;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 创建登录连接url
 * @author 王明伟
 *
 */
@Setter
@Getter
@Slf4j
public class CreateLoginUrlRes extends BaseParam {

	private String ticket; 
	private String sign;
	
	private String url;
	
	/**
	 * 生成签名
	 */
	public void createSign(String appsecret) {
		String key = getAppid()+getNonce()+ticket+getTime()+appsecret;
		log.info("待签名的数据：{}",key);
		sign = MD5.getMD5(key);
	}
	
	public static void main(String[] args) {
		CreateLoginUrlRes r = new CreateLoginUrlRes();
		r.setAppid("nzT7XmGAVQKt88us");
		r.setNonce("w0JrigAAUR7l2mZ4t3iBztA9HQ2dLXkc");
		r.setTicket("hsu8yNGinQTMMYTuxvRG2Iej4i1wHXcL");
		r.setTime(1664506302083L);
		r.createSign("igPxotNc6SKNCAFz");
		System.out.println(JSONUtil.toJSONString(r, true));
	}
	
	public void createVisitUrl(String visitUrl) {
		String s = "VISIT_URLthreepartylogin_v2.html?" + 
				"appid=APPID&nonce=NONCE&ticket=TICKET" + 
				"&time=TIME&sign=SIGN";
		s = s.replace("VISIT_URL", visitUrl)
				.replace("APPID", getAppid())
				.replace("NONCE", getNonce())
				.replace("TICKET", getTicket())
				.replace("TIME", getTime()+"")
				.replace("SIGN", getSign())
				;
		url = s;
	}
}
